package com.wanbatv.wangwangba.model.imple;

import android.content.Context;

import com.wanbatv.wangwangba.model.DogtvModel;
import com.wanbatv.wangwangba.model.OnDogtvListener;
import com.wanbatv.wangwangba.model.entity.DogtvComprehensiveData;
import com.wanbatv.wangwangba.model.entity.DogtvContentData;
import com.wanbatv.wangwangba.model.entity.DogtvExhibitionData;
import com.wanbatv.wangwangba.model.entity.DogtvLeisureData;
import com.wanbatv.wangwangba.model.entity.DogtvSportsData;
import com.wanbatv.wangwangba.util.Config;
import com.wanbatv.wangwangba.util.GitDogtvService;
import com.wanbatv.wangwangba.util.HeaderClient;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 俞亚楠 on 2016/7/26.
 */
public class DogtvModelImple implements DogtvModel {
    Context context;
    public DogtvModelImple(Context context){
        this.context=context.getApplicationContext();
    }
    Retrofit retrofit =new Retrofit.Builder()
            .baseUrl(Config.httpUrl())
            .addConverterFactory(GsonConverterFactory.create())
            .client(HeaderClient.genericClient())
            .build();
    GitDogtvService api=retrofit.create(GitDogtvService.class);


    @Override
    public void setComprehensiveData(final OnDogtvListener onDogtvListener) {
        api.getDogtvComprehensive().enqueue(new Callback<DogtvContentData>() {
            @Override
            public void onResponse(Call<DogtvContentData> call, Response<DogtvContentData> response) {
                List<DogtvContentData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onDogtvListener.onLoadDogtvComprehensiveData(listBeen);
            }

            @Override
            public void onFailure(Call<DogtvContentData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setLeisureData(final OnDogtvListener onDogtvListener) {
        api.getDogtvLeisure().enqueue(new Callback<DogtvContentData>() {
            @Override
            public void onResponse(Call<DogtvContentData> call, Response<DogtvContentData> response) {
                List<DogtvContentData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onDogtvListener.onLoadDogtvLeisureData(listBeen);
            }

            @Override
            public void onFailure(Call<DogtvContentData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setSportsData(final OnDogtvListener onDogtvListener) {
        api.getDogtvSports().enqueue(new Callback<DogtvContentData>() {
            @Override
            public void onResponse(Call<DogtvContentData> call, Response<DogtvContentData> response) {
                List<DogtvContentData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onDogtvListener.onLoadDogtvSportsData(listBeen);
            }

            @Override
            public void onFailure(Call<DogtvContentData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setExhibitionData(final OnDogtvListener onDogtvListener) {
        api.getDogtvExhibition().enqueue(new Callback<DogtvContentData>() {
            @Override
            public void onResponse(Call<DogtvContentData> call, Response<DogtvContentData> response) {
                List<DogtvContentData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onDogtvListener.onLoadDogtvExhibitionData(listBeen);
            }

            @Override
            public void onFailure(Call<DogtvContentData> call, Throwable t) {

            }
        });
    }
}
